// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:equatable/equatable.dart';
import 'package:f200/features/cart/domain/cart_item_model.dart';
import 'package:json_annotation/json_annotation.dart';

part 'cart_model.g.dart';

@JsonSerializable()
class CartModel extends Equatable {
  CartModel({
    required this.discounts,
    required this.items,
    this.allIsSelected = false,
    this.selectedTotal = 0,
  });

  String discounts;
  List<CartItemModel> items;
  bool allIsSelected;
  int selectedTotal;

  factory CartModel.fromJson(Map<String, dynamic> json) =>
      _$CartModelFromJson(json);
  Map<String, dynamic> toJson() => _$CartModelToJson(this);

  CartModel copyWith({
    String? discounts,
    List<CartItemModel>? items,
    bool? allIsSelected,
    int? selectedTotal,
  }) {
    return CartModel(
      discounts: discounts ?? this.discounts,
      allIsSelected: allIsSelected ?? this.allIsSelected,
      items: items ?? this.items,
      selectedTotal: selectedTotal ?? this.selectedTotal,
    );
  }

  @override
  List<Object?> get props => [allIsSelected, selectedTotal, discounts, items];

  @override
  bool? get stringify => true;
}
